package structs.term;

import java.util.HashMap;

import exception.InvalidNameException;
import exception.InvalidTermException;

/**
 * Contains adoption information for previous terms
 * @author SJP
 */
public class PrevTerms extends HashMap<String,Term>{
	
	/**
	 * @param id the term to get
	 * @return the term referenced by id
	 * @throws InvalidNameException if there is no term with the given id.
	 */
	public Term getTerm(String id) throws InvalidNameException{
		if (super.containsKey(id))
			return super.get(id);
		else
			throw new InvalidNameException("PrevTerms: getTerm: \""+id+"\" does not exist.");
	}
	
	/**
	 * Add a term to the previous term records
	 * @param t the term to add
	 * @return the term added
	 * @throws InvalidTermException if the term already exists.
	 */
	public Term addTerm(Term t) throws InvalidTermException{
		if (super.containsValue(t))
			throw new InvalidTermException("PrevTerms: addTerm: \""+t.toString()+"\" already exists.");
		else {
			super.put(t.toString(), t);
			return t;
		}
	}
}
